
/*
 * 二期中页面验证
 * 
 */
 //验证是否为空
function validateEmpty_jquery(name,id){
  var ob = $("#"+id);
  var value = $.trim(ob.val());
  if(value==""){
   setValidateErrorStyle_jquery(ob);
   alert(name+": 不能为空！");
   return false;
  }else{
   return true;
  }
}

//验证长度
function validateMaxLength_jquery(name,id,maxlength){
  var ob = $("#"+id);
  var length = $.trim(ob.val()).length;
  if(length>maxlength){
   setValidateErrorStyle_jquery(ob);
   alert(name + ": 输入数据长度不能大于 " + maxlength);
   return false;
  }else{
   return true;
  }
}

//出错时设置边框为红色
function setValidateErrorStyle_jquery(field) {
	field.css("border","1 solid red");
	//var field = document.getElementById(id);
	//field.style.border="1 solid red";
	field.focus();
}
//验证数字
function validateNumber_jquery(name,id){
	var ob = $("#"+id);
	var value = $.trim(ob.val());
	//var patten = new RegExp(/^[1-9][0-9]*$/);
	var patten = new RegExp(/^(([1-9]{1}\d*)|0)(\.\d+)?$/);
	///^-?(([1-9]{1}\d*)|0)(\.\d+)?$/gi;
	//alert(patten.test(value));
	if( value!='' && !patten.test(value)){
	   setValidateErrorStyle_jquery(ob);
	   alert(name+": 必须是数字！");
	   return false;
	}else{
	   return true;
	}
}

//验证数字
function validateNumber_Integer(name,id){
	var ob = $("#"+id);
	var value = $.trim(ob.val());
	//var patten = new RegExp(/^[1-9][0-9]*$/);
	var patten = new RegExp(/^(([1-9]{1}\d*)|0)$/);
	///^-?(([1-9]{1}\d*)|0)(\.\d+)?$/gi;
	//alert(patten.test(value));
	if( value!='' && !patten.test(value)){
	   setValidateErrorStyle_jquery(ob);
	   alert(name+": 必须是整数！");
	   return false;
	}else{
	   return true;
	}
}

//比较两个日期格式
function compareDate_jquery(startDateId,startName,endDateId,endName){
    var startDateStr = $("#"+startDateId).val();
    var endDateOb = $("#"+endDateId);
    var endDateStr = endDateOb.val();
    startDateStr = startDateStr.replace(/-/g,"/");
    endDateStr = endDateStr.replace(/-/g,"/");
    if(startDateStr=="" || endDateStr ==""){
      return true;
    }
    var startDate = new Date(startDateStr);
    var startDateTime = startDate.getTime();
    var endDate = new Date(endDateStr);
    var endDateTime = endDate.getTime();
	if( startDateTime > endDateTime){
	   endDateOb.css("border","1 solid red");
	   alert(endName+": 不能小于 "+startName);
	   return false;
	}else{
	   return true;
	}
}
